

//调用
$(document).ready(function(){
    $('#login_form').bind('submit', function(){
        login_submit(this, function(data){
            console.log(JSON.stringify(data));
            var res = data;
            if(res.success) // 成功
            {
                /*var token =  res.data.access_token.token;
                var refresh_token = res.data.refresh_token.token;
                console.log("token: "+token);
                console.log("r_token: " + refresh_token);

                window.localStorage.setItem("token", token);
                window.localStorage.setItem("refresh_token", refresh_token);
                window.localStorage.setItem("user_id", user_id);*/

                SetUserParam(res.data, user_id);

                window.location.href="./htmls/main.html";
            }
            else
            {
                /*$('#res_info').html(res.message);
                $('.regist-wrap-dialog').css("display", "flex");*/
                MessageBox("show", "发生错误", res.message);
            }

            //

        }, function (err) {
            alert(err);
        });
        return false;
    });
});

//将form转为AJAX提交
var user_id="";
function login_submit(frm, fn, err) {
    var dataPara = getFormJson(frm);

    user_id = dataPara.login_id;
    dataPara.login_password = hex_md5(dataPara.login_password);
    console.log(dataPara);

    $.ajax({
        url: frm.action,
        xhrFields:{withCredentials:true},
        type: frm.method,
        data: dataPara,
        success: fn,
        error : err
    });
}


function getVerify2(obj){
    obj.src = "http://47.104.102.188:7979/fitool/auth/verifyCode?"+Math.random();
}
